/************************************************************************
                                                                     
   Xceed Ultimate ListBox for Silverlight                                                                                                                                            
   Copyright (C) 2010 Xceed Software Inc.    
                                                                     
   This program is provided to you under the terms of the GNU General Public  
   License version 2 as published by the Free Software Foundation. 
        
   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY, without even the implied warranty of 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License along 
   with this program, if not, write to the Free Software Foundation, Inc., 
   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

   This program can be provided to you by Xceed Software Inc. under a
   proprietary commercial license agreement for use in non-Open Source
   projects. Visit Xceed.com to find the commercial edition of 
   Xceed Ultimate ListBox for Silverlight.                                    
                                                                      
 **********************************************************************/

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;

// Original code comments:
// PathGeometryHelper.cs by Charles Petzold, December 2007
//
// This source code obtained from MSDN Magasine Code Foundation (March 2008) and 
// the URL is http://msdn.microsoft.com/en-us/magazine/cc337985.aspx?code=true&level=root,Petzold.Shapes&file=PathGeometryHelper.cs.

namespace Xceed.Silverlight.Utils
{
  internal static class GeometryHelper
  {
    public static List<Point> GetPointsOnFlattenedPath( PathGeometry flattenedPath )
    {
      List<Point> flattenedPathPoints = new List<Point>();

      // For flattened geometry there should be just one PathFigure in the Figures
      if( flattenedPath.Figures.Count != 1 )
        return new List<Point>();

      PathFigure pathFigure = flattenedPath.Figures[ 0 ];

      flattenedPathPoints.Add( pathFigure.StartPoint );

      // SegmentsCollection should contain PolyLineSegment and LineSegment
      foreach( PathSegment pathSegment in pathFigure.Segments )
      {
        if( pathSegment is PolyLineSegment )
        {
          PolyLineSegment seg = pathSegment as PolyLineSegment;
          flattenedPathPoints.AddRange( seg.Points );
        }
        else if( pathSegment is LineSegment )
        {
          LineSegment seg = pathSegment as LineSegment;
          flattenedPathPoints.Add( seg.Point );
        }
        else
        {
          throw new Exception( "GetIntersectionPoint - unexpected path segment type: " + pathSegment.ToString() );
        }
      }

      return ( flattenedPathPoints );
    }
  }
}
